from config import Config
from app import db
from .models import Device
#from flask.cli import with_appcontext


#@with_appcontext
def init_devices():
    # 删除现有设备记录
    Device.query.delete()
    
    # 遍历DEVICES字典，创建新设备
    for device_id in Config.DEVICES:
        device = Device(id=device_id)
        db.session.add(device)
    
    # 提交事务
    db.session.commit()